home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / w00w00 / w00aimexp / login.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-01-02  |  4.2 KB  |  159 lines

  1. /*
  2.  * Most of the stuff used for login.
  3.  *
  4.  */
  5.  
  6. #include "w00aimexp.h"
  7.  
  8. static int w00aimexp_parse_login(aim_session_t *sess, aim_frame_t *fr, ...)
  9. {
  10.     struct w00aimexp_priv *priv = (struct w00aimexp_priv *)sess->aux_data;
  11.     struct client_info_s info = AIM_CLIENTINFO_KNOWNGOOD;
  12.     char *key;
  13.     va_list ap;
  14.  
  15.     va_start(ap, fr);
  16.     key = va_arg(ap, char *);
  17.     va_end(ap);
  18.  
  19.     aim_send_login(sess, fr->conn, priv->screenname, priv->password, &info, key);
  20.     return 1;
  21. }
  22.  
  23. /*
  24.  * This marks the end of authorization, and probably the beginning of BOS.
  25.  *
  26.  * If there was an error, everything ends here.  Otherwise, we use the cookie
  27.  * and IP from the authorizer to connect to our assigned BOS.  This connection
  28.  * will be used for the major stuff.  New connections may be opened later for
  29.  * things like chat.
  30.  *
  31.  */
  32. static int w00aimexp_parse_authresp(aim_session_t *sess, aim_frame_t *fr, ...)
  33. {
  34.     va_list ap;
  35.     aim_conn_t *bosconn;
  36.     char *sn, *bosip, *errurl, *email;
  37.     fu8_t *cookie;
  38.     int errorcode, regstatus;
  39.     int latestbuild, latestbetabuild;
  40.     char *latestrelease, *latestbeta;
  41.     char *latestreleaseurl, *latestbetaurl;
  42.     char *latestreleaseinfo, *latestbetainfo;
  43.  
  44.     va_start(ap, fr);
  45.     sn = va_arg(ap, char *);
  46.     errorcode = va_arg(ap, int);
  47.     errurl = va_arg(ap, char *);
  48.     regstatus = va_arg(ap, int);
  49.     email = va_arg(ap, char *);
  50.     bosip = va_arg(ap, char *);
  51.     cookie = va_arg(ap, fu8_t *);
  52.  
  53.     latestrelease = va_arg(ap, char *);
  54.     latestbuild = va_arg(ap, int);
  55.     latestreleaseurl = va_arg(ap, char *);
  56.     latestreleaseinfo = va_arg(ap, char *);
  57.  
  58.     latestbeta = va_arg(ap, char *);
  59.     latestbetabuild = va_arg(ap, int);
  60.     latestbetaurl = va_arg(ap, char *);
  61.     latestbetainfo = va_arg(ap, char *);
  62.  
  63.     va_end(ap);
  64.  
  65.     dvprintf("Screen name: %s\n", sn);
  66.  
  67.     /*
  68.      * Check for error.
  69.      */
  70.     if (errorcode || !bosip || !cookie)
  71.     {
  72.         fprintf(stderr, "Error logging in (error code 0x%04x)\n", errorcode);
  73.         fprintf(stderr, "Error URL: %s\n", errurl);
  74.         aim_conn_kill(sess, &fr->conn);
  75.         exit(ERROR);
  76.     }
  77.  
  78.     dvprintf("Registration status: %2d\n", regstatus);
  79.     dvprintf("Email: %s\n", email);
  80.     dvprintf("BOS IP: %s\n", bosip);
  81.  
  82.     if (latestbeta)
  83.     {
  84.         dvprintf("Latest beta version: %s, build %d, at %s (more info at %s)\n", latestbeta, latestbetabuild, latestbetaurl, latestbetainfo);
  85.     }
  86.     
  87.     if (latestrelease)
  88.     {
  89.         dvprintf("Latest released version: %s, build %d, at %s (more info at %s)\n", latestrelease, latestbuild, latestreleaseurl, latestreleaseinfo);
  90.     }
  91.     
  92.     dprintf("Closing auth connection\n");
  93.     aim_conn_kill(sess, &fr->conn);
  94.  
  95.     if (!(bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, bosip)))
  96.     {
  97.         dprintf("Error: could not connect to BOS: internal error\n");
  98.         return 1;
  99.     }
  100.     else if (bosconn->status & AIM_CONN_STATUS_CONNERR)
  101.     {    
  102.         dprintf("Error: could not connect to BOS\n");
  103.         aim_conn_kill(sess, &bosconn);
  104.         return 1;
  105.     }
  106.  
  107.     addcb_bos(sess, bosconn);
  108.     aim_auth_sendcookie(sess, bosconn, cookie);
  109.  
  110.     return 1;
  111. }
  112.  
  113. int login(aim_session_t *sess, const char *sn, const char *passwd)
  114. {
  115.     struct w00aimexp_priv *priv = (struct w00aimexp_priv *)sess->aux_data;
  116.     aim_conn_t *authconn;
  117.  
  118.     if (sn) priv->screenname = strdup(sn);
  119.     if (passwd) priv->password = strdup(passwd);
  120.  
  121.     if (!priv->screenname || !priv->password)
  122.     {
  123.         fprintf(stderr, "Error: need screen name and password\n");
  124.         exit(ERROR);
  125.     }
  126.  
  127.     if (!(authconn = aim_newconn(&g_session, AIM_CONN_TYPE_AUTH, 
  128.             priv->server ? priv->server : FAIM_LOGIN_SERVER)))
  129.     {
  130.         fprintf(stderr, "Error: internal connection error during login\n");
  131.         exit(ERROR);
  132.     }
  133.     else if (authconn->fd == ERROR)
  134.     {
  135.         if (authconn->status & AIM_CONN_STATUS_RESOLVERR)
  136.         {
  137.             fprintf(stderr, "Error: could not resolve authorizer name\n");
  138.         }
  139.         else if (authconn->status & AIM_CONN_STATUS_CONNERR)
  140.         {
  141.             fprintf(stderr, "Error: could not connect to authorizer\n");
  142.         }
  143.         aim_conn_kill(sess, &authconn);
  144.         exit(ERROR);
  145.     }
  146.  
  147.     aim_conn_addhandler(sess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNCOMPLETE, w00aimexp_conncomplete, 0);
  148.     aim_conn_addhandler(sess, authconn, 0x0017, 0x0007, w00aimexp_parse_login, 0);
  149.     aim_conn_addhandler(sess, authconn, 0x0017, 0x0003, w00aimexp_parse_authresp, 0);    
  150.  
  151.     /* If the connection is in progress, this will just be queued */
  152.     aim_request_login(sess, authconn, priv->screenname);
  153.  
  154.     dprintf("Login request sent\n");
  155.     return 0;
  156. }
  157.  
  158.  
  159.